<?php
namespace Home\Controller;

class VideoController extends HomeController {

    public function index(){
        $authors = M('author')->select();
        $this->assign('authors',$authors);
        if(empty($_GET['aid'])){
        $list = M('video')->select();
        $this->assign('list',$list);
    }else{
        $aid = $_GET['aid'];
        $where['v_pid'] = array('eq',$aid);
        $list = M('video')->where($where)->select();
        $this->assign('list',$list);
    }
    $this->display();

    }
    public function play(){
        $vid = $_GET['vid'];
        $data = M('video')->find($vid);
        // var_dump($_SESSION);die;
        $uid = $_SESSION['uid'];
        if($_SESSION['nickname']==null){
            $name = $_SESSION['email'];
        }else{
            $name = $_SESSION['nickname'];
        }
        $this->assign('title',$data['v_title']);
        $this->assign('src',$data['v_src']);
        $this->assign('vid',$data['v_id']);
        $this->assign('name',$name);
        $this->assign('uid',$uid);

        $video = M('video_comment');
        $where['v_id'] = $data['v_id'];
        $list = $video->where()->select();
        $this->assign('list',$list);
        // var_dump($list);die;
        $this->display('play');
    }
    public function comment(){
        // var_dump($_POST);die;
        $comment = M('video_comment');
        $_POST['sendTime'] = date('Y-m-d H:i',time());
        $re = $comment->create();
        if($re>0){
        $comment->add();
        echo "<div id='comment' style='background-color:#282B2F; float: left;width: 680px; margin-top: 5px;margin-bottom: 5px;'>
        <span style='color: blue'>{$_POST['sender']}:</span>
        <p style='display: block;margin-left: 50px;'>{$_POST['comment']}</p>
        <span style='margin-left: 550px;color: grey'>{$_POST['sendTime']}</span>
      </div>";
        }else{
            return false;
        }
    }

}